package com.packet.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.packet.pojo.Customs;
import com.packet.pojo.Trip;
import com.packet.service.StaffCustomsService;
import com.packet.service.StaffExamineService;
import com.packet.service.StaffTripService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @className:ToFinanceAndManager
 * @Author:wallet_packet Date:2023-12-11 19:02
 * @Describe:
 */
@Controller
public class ToFinanceAndManager {
    @Autowired
    StaffCustomsService staffCustomsService;

    @Autowired
    StaffTripService staffTripService;

    @RequestMapping("/tofinanceAndManager/{bid}")
    @ResponseBody
    @HystrixCommand(fallbackMethod = "ErrorResponse")

    public List<Customs> getCustoms(@PathVariable("bid") Integer bid){
        System.out.println(staffCustomsService.getAllCustoms(bid));
        List<Customs> allCustoms = staffCustomsService.getAllCustoms(bid);
        if(allCustoms.size()==0){
            System.out.println("错了错了啊");
            throw new RuntimeException("运行异常");
        }
        return allCustoms;
    }

    public List<Customs> ErrorResponse(@PathVariable("bid") Integer bid){
        List<Customs> customs = new ArrayList<>();
        Customs custom = new Customs();
        custom.setCdetail("读取信息错误");
        customs.add(custom);
        return customs;
    }

    @RequestMapping("/manager/TripToManager/{bid}")
    @ResponseBody
    public Trip getTripToManager(@PathVariable("bid") Integer bid){
        Trip detailTrip = staffTripService.getDetailTrip(bid);
        //List<Customs> customs = staffCustomsService.getCustoms(bid);
        //List<Customs> customsThen = staffCustomsService.getCustomsThen(bid);
        //model.addAttribute("detailTrip",detailTrip);
        //model.addAttribute("detailCustoms",customs);
        //model.addAttribute("detailCustomsThen",customsThen);
        //System.out.println("进入成功。。。。");
        return detailTrip;
    }

    @RequestMapping("/manager/CustomsToManager/{bid}")
    @ResponseBody
    public List<Customs> getCustomsToManager(@PathVariable("bid") Integer bid){
        List<Customs> customs = staffCustomsService.getCustoms(bid);
        return customs;
    }

    @RequestMapping("/manager/CustomsThenToManager/{bid}")
    @ResponseBody
    public List<Customs> getCustomsThenToManager(@PathVariable("bid") Integer bid){
        List<Customs> customsThen = staffCustomsService.getCustomsThen(bid);
        return customsThen;
    }
}
